//
//  AppOpenSystemSettingsManager.swift
//  XiaoweHealthy
//
//  Created by Riven on 2022/10/22.
//

import Foundation
import UIKit


/// 跳转系统设置
open class AppOpenSystemSettingsManager {
    
    /// 打开 App 设置
    /// - Returns: 是否能打开
    @discardableResult
    public class func openAppSettings() -> Bool {
        openSystemSettings(UIApplication.openSettingsURLString)
    }
    
    /// 跳转的模版
    /// - Parameters:
    ///     - settingsPath: 打开路径
    /// - Returns: 是否能打开
    @discardableResult
    public class func openSystemSettings(_ settingsPath: String) -> Bool {
        let tUrl = URL(string: settingsPath)
        guard let url = tUrl else {
            return false
        }
        
        let canOpen = UIApplication.shared.canOpenURL(url)
        
        print("打开系统设置 - url = \(url), canOpen = \(canOpen)")
        
        if canOpen {
            UIApplication.shared.open(url, options: [:], completionHandler: nil)
        }
        
        return canOpen
    }
    
}

public extension AppOpenSystemSettingsManager {
    
    /**
     "个人热点":"prefs:root=INTERNET_TETHERING",
     "WIFI设置":"prefs:root=WIFI",
     "蓝牙设置":"prefs:root=Bluetooth",
     "系统通知":"prefs:root=NOTIFICATIONS_ID",
     "通用设置":"prefs:root=General",
     "显示设置":"prefs:root=DISPLAY&BRIGHTNESS",
     "壁纸设置":"prefs:root=Wallpaper",
     "声音设置":"prefs:root=Sounds",
     "隐私设置":"prefs:root=privacy",
     "蜂窝网路":"prefs:root=MOBILE_DATA_SETTINGS_ID",
     "音乐":"prefs:root=MUSIC",
     "APP Store":"prefs:root=STORE",
     "Notes":"prefs:root=NOTES",
     "Safari":"prefs:root=Safari",
     "Music":"prefs:root=MUSIC",
     "photo":"prefs:root=Photos"
     */
    
//    private static let kSystemSettingsPath = "App-Prefs:root"
    
    private static let kSystemSettingsPath1 = "App-Prefs://"

//    private static let kSystemSettingsPath2 = "App-Settings://"
    
    /// 打开设置界面
    /// - Returns: 是否能打开
    @discardableResult
    class func openSystemSetting() -> Bool {
        openSystemSettings(kSystemSettingsPath1)
    }
    
}
